﻿using Harmontronics.Model.Entitys;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Microsoft.Extensions.Configuration;
using System;
using System.Globalization;
using System.Linq;

namespace Harmontronics.Repository
{
    public class HcDbContext : DbContext
    { 
        public HcDbContext(DbContextOptions<HcDbContext> options) : base(options)
        {
            //this.Database.EnsureCreated();
        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //modelBuilder.Entity<UserRecipe>().ToTable("userrecipes");
            //// 联合主键
            //modelBuilder.Entity<UserRecipe>()
            //.HasKey(p => new { p.RecipeId, p.ParameterId });
            modelBuilder.Entity<UserRecipe>().HasKey(p => new { p.ParameterId, p.RecipeId });
            //modelBuilder.Entity<MenuRoleRelation>().HasKey(pk => new { pk.RoleId, pk.MenuId });
            //modelBuilder.Entity<UserRoleRelation>().HasKey(pk => new { pk.RoleId, pk.UserId });
        }

        public DbSet<Menu>? Menu { get; set; }
        public DbSet<Users>? Users { get; set; }
        public DbSet<Role>? Roles { get; set; }
        public DbSet<UserRoleRelation>? UserRoleRelation { get; set; }
        public DbSet<MenuRoleRelation>? MenuRoleRelation { get; set; }
        public DbSet<PlcSetting>? PlcSettings { get; set; }
        public DbSet<Process>? Processes { get; set; }
        public DbSet<ProductionLine>? ProductionLines { get; set; }
        public DbSet<Station>? Stations { get; set; }
        public DbSet<WorkShop>? WorkShops { get; set; }

        public DbSet<Material>? Materials { get; set; }
        public DbSet<Part>? Parts { get; set; }
        public DbSet<RecipeConfig>? RecipeConfigs { get; set;}
        public DbSet<Recipe>? Recipes { get; set; }
        public DbSet<UserRecipe>? UserRecipes { get; set; }
        public DbSet<RecipeType>? RecipeTypes { get; set; }

    }
}
